package com.tongtech.space.common.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 过滤器demo
 * 注解@WebFilter用于自动注册过滤器,省去了FilterConfig中手动配置Bean的步骤,二选一即可
 *
 * @author jinjiayu
 * @since 2021/2/3
 */
@Slf4j
//@WebFilter(urlPatterns = "/*", filterName = "filterDemo")
public class FilterDemo implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // TODO 具体的过滤器业务处理
        log.debug("过滤器开始执行...");

        // 最后将请求和响应传递给过滤器链中
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
